package com.sojson.config.mybatis.interceptor;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;

/**
 * Mybatis顶级拦截器
 * 
 * @author liu
 * @date 2022-01-20
 */
// @Component
@SuppressWarnings("rawtypes")
public class CustInnerInterceptor implements InnerInterceptor {

    /**
     * 是否执行查询语句,如果为false,所有的查询语句不执行
     */
    @Override
    public boolean willDoQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds,
        ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
        return true;
    }

    /**
     * 修改查询的Sql语句,前提是{@link com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor#willDoQuery()}返回true
     */
    @Override
    public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds,
        ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
        InnerInterceptor.super.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql);
    }

    /**
     * 是否执行添加,修改,删除语句,如果为false,所有的...语句不执行
     */
    @Override
    public boolean willDoUpdate(Executor executor, MappedStatement ms, Object parameter) throws SQLException {
        return InnerInterceptor.super.willDoUpdate(executor, ms, parameter);
    }

    /**
     * 修改添加,修改,删除的Sql语句,前提是{@link com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor#willDoUpdate()}返回true
     */
    @Override
    public void beforeUpdate(Executor executor, MappedStatement ms, Object parameter) throws SQLException {
        InnerInterceptor.super.beforeUpdate(executor, ms, parameter);
    }

    /**
     * 修改Sql语句,此时的Sql语句已经将参数转为?号
     */
    @Override
    public void beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout) {
        InnerInterceptor.super.beforePrepare(sh, connection, transactionTimeout);
    }

    /**
     * 修改Sql语句,此时的Sql语句已经将参数转为?号
     */
    @Override
    public void beforeGetBoundSql(StatementHandler sh) {
        InnerInterceptor.super.beforeGetBoundSql(sh);
    }

    /**
     * 暂时没执行过
     */
    @Override
    public void setProperties(Properties properties) {
        InnerInterceptor.super.setProperties(properties);
    }

}